import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class Home1_3Page extends StatefulWidget {
  const Home1_3Page({Key? key}) : super(key: key);

  @override
  State<Home1_3Page> createState() => _Home1_3PageState();
}

class _Home1_3PageState extends State<Home1_3Page> {
  @override
  void initState() {
    super.initState();
    // 设置状态栏颜色
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Color(0xFF1DC4A0),
      statusBarIconBrightness: Brightness.light,
    ));
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // 确保在页面切换时也保持状态栏颜色
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Color(0xFF1DC4A0),
      statusBarIconBrightness: Brightness.light,
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        children: [
          // 顶部区域
          Container(
            width: double.infinity,
            padding: EdgeInsets.only(
              top: MediaQuery.of(context).padding.top,
              left: 20,
              right: 20,
              bottom: 20,
            ),
            decoration: const BoxDecoration(
              color: Color(0xFF1DC4A0),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const Text(
                  '您好，用户A',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 5),
                const Text(
                  '祝您身体健康！',
                  style: TextStyle(
                    color: Colors.white70,
                    fontSize: 16,
                  ),
                ),
              ],
            ),
          ),

          // 主体内容
          Expanded(
            child: SingleChildScrollView(
              child: Padding(
                padding: const EdgeInsets.all(20),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    // 功能卡片区域
                    _buildServiceCard(
                      title: '健康追踪',
                      description: '记录您的健康数据',
                      icon: 'assets/icons/health_tracking.png',
                      onTap: () =>
                          Navigator.pushNamed(context, '/health_tracking'),
                    ),
                    const SizedBox(height: 20),
                    _buildServiceCard(
                      title: '服药日程',
                      description: '管理您的用药计划',
                      icon: 'assets/icons/medication.png',
                      onTap: () =>
                          Navigator.pushNamed(context, '/medication_schedule'),
                    ),
                    const SizedBox(height: 20),
                    _buildServiceCard(
                      title: '健康报告',
                      description: '查看您的健康报告',
                      icon: 'assets/icons/report.png',
                      onTap: () =>
                          Navigator.pushNamed(context, '/report_category'),
                    ),
                  ],
                ),
              ),
            ),
          ),

          // 底部导航栏
          Container(
            padding: const EdgeInsets.symmetric(vertical: 12),
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.1),
                  blurRadius: 10,
                  offset: const Offset(0, -2),
                ),
              ],
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                _buildNavItem(
                  iconPath: 'assets/icons/home.png',
                  label: '首页',
                  isSelected: true,
                  onTap: () {},
                ),
                _buildNavItem(
                  iconPath: 'assets/icons/calendar.png',
                  label: '服药日程',
                  isSelected: false,
                  onTap: () => Navigator.pushReplacementNamed(
                      context, '/medication_schedule'),
                ),
                _buildNavItem(
                  iconPath: 'assets/icons/notification.png',
                  label: '消息',
                  isSelected: false,
                  onTap: () =>
                      Navigator.pushReplacementNamed(context, '/notification'),
                ),
                _buildNavItem(
                  iconPath: 'assets/icons/profile.png',
                  label: '我的',
                  isSelected: false,
                  onTap: () =>
                      Navigator.pushReplacementNamed(context, '/profile'),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildServiceCard({
    required String title,
    required String description,
    required String icon,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.all(20),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(15),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 10,
              offset: const Offset(0, 2),
            ),
          ],
        ),
        child: Row(
          children: [
            Image.asset(
              icon,
              width: 40,
              height: 40,
            ),
            const SizedBox(width: 20),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    title,
                    style: const TextStyle(
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SizedBox(height: 5),
                  Text(
                    description,
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.grey[600],
                    ),
                  ),
                ],
              ),
            ),
            const Icon(
              Icons.arrow_forward_ios,
              color: Colors.grey,
              size: 20,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildNavItem({
    required String iconPath,
    required String label,
    required bool isSelected,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Image.asset(
            iconPath,
            width: 24,
            height: 24,
            color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
          ),
          const SizedBox(height: 8),
          Text(
            label,
            style: TextStyle(
              color: isSelected ? const Color(0xFF1DC4A0) : Colors.grey,
              fontSize: 12,
              fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
            ),
          ),
        ],
      ),
    );
  }
}
